/* Check JER_Bitmatrix_Dotprod(). */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include "reed_sol-2.h"
#include "jerasure-2.h"
#include "galois-2.h"

using namespace std;

int main( int argc, char** argv )
{
	JER_Bitmatrix *jbm;
	JER_Matrix *jm2;
	JER_Slices *slices;
	int i, j;

	int m = atoi( argv[1] );
	int k = atoi( argv[2] );
	int w = atoi( argv[3] );
	unsigned char* buffer;
	int size;

	slices = new JER_Slices();
	slices->W = w;
	slices->K = k;
	slices->M = m;
	slices->PS = 8;
	slices->size = slices->PS * w;
	size = slices->size;
	slices->ptrs.resize( k + m );
	slices->failures.resize( k + m );
	buffer = (unsigned char*) malloc( sizeof(char) * (k+m) * size );
	srand48(m);
	for( i = 0; i < k*size; i++ )
	{
		buffer[i] = lrand48() % 256;
		if( i % size == 0 )
			fprintf( stdout, "\n" );
		fprintf( stdout, "%x", buffer[i] );
	}
	fprintf( stdout, "\n" );
	for( i = 0; i < k+m; i++ )
	{
		slices->ptrs[i] = buffer + i * size;
		slices->failures[i] = ( i < k ) ? 0 : 1;
	}

	jbm = new JER_Bitmatrix( m, k, w );
	for( i = 0; i < m*w; i++ )
		for( j = 0; j < k*w; j++ )
			jbm->Set( i, j, lrand48() % 2 );

	for( i = 0; i < m; i++ )
		JER_Bitmatrix_Dotprod( slices, jbm, i, NULL, i+k );

	for( i = 0; i < (k+m)*size; i++ )
	{
		if( i % size == 0 )
			fprintf( stdout, "\n" );
		fprintf( stdout, "%x", buffer[i] );
	}
	fprintf( stdout, "\n" );
	return 0;
}
